import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
import store from "@/store";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/login",
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/login/login.vue"),
  },
  {
    path: "/privacy",
    name: "privacy",
    component: () => import("@/views/privacy/privacy.vue"),
  },
  {
    path: "/user",
    name: "user",
    component: () => import("@/views/privacy/user.vue"),
  },
  {
    path: "/authorization",
    name: "authorization",
    component: () => import("@/views/privacy/authorization.vue"),
  },
  {
    path: "/trade",
    name: "trade",
    component: () => import("@/views/privacy/trade.vue"),
  },
  {
    path: "/home",
    name: "home",
    component: HomeView,
    children: [
      {
        type: "menu-item",
        path: "index",
        component: () => import("../views/index/Index.vue"),
        meta: {
          thumb: [
            {
              text: "概况",
              to: "/home/index",
            },
          ],
        },
      },
      {
        type: "sub-memu",
        name: "analysis",
        path: "analysis",
        component: () => import("../views/analysis/analysis.vue"),
        meta: {
          thumb: [{ text: "数据概览", to: "/home/analysis" }],
          keepAlive: false,
        },
      },
      {
        type: "sub-memu",
        name: "vehicleSafetyManagement",
        path: "vehicleSafetyManagement",
        component: () => import("../views/link/vehicleSafetyManagement.vue"),
        meta: {
          thumb: [
            { text: "车辆安全管理", to: "/home/vehicleSafetyManagement" },
          ],
          keepAlive: false,
        },
      },
      {
        type: "sub-memu",
        name: "fleetList",
        path: "fleetManagement/list",
        component: () => import("../views/fleetManagement/fleetList.vue"),
        meta: {
          //thumb: ["车队管理", "车队列表"],
          thumb: [{ text: "车队管理", to: "/home/fleetManagement/list" }],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      {
        type: "sub-memu",
        name: "fleetDetails",
        path: "fleetManagement/details",
        component: () => import("../views/fleetManagement/fleetDetails.vue"),
        meta: {
          //thumb: ["车队管理", "车队列表", "详情"],
          thumb: [
            { text: "车队列表", to: "/home/fleetManagement/list" },
            { text: "详情", to: null },
          ],
          keepAlive: false,
        },
      },
      /* 承运订单 */
      /* 承运订单 订单是订单订单 */
      {
        type: "sub-memu",
        name: "carrierOrderList",
        path: "carrierOrder/list",
        component: () => import("../views/carrierOrder/carrierOrder.vue"),
        meta: {
          //thumb: ["承运订单", "承运订单管理"],
          thumb: [{ text: "承运订单管理", to: "/home/carrierOrder/list" }],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      {
        type: "sub-memu",
        name: "CarrierOrderDetails",
        path: "carrierOrder/details",
        component: () =>
          import("../views/carrierOrder/CarrierOrderDetails.vue"),
        meta: {
          //thumb: ["承运订单", "承运订单管理", '订单详情'],
          thumb: [
            { text: "承运订单管理", to: "/home/carrierOrder/list" },
            { text: "订单详情", to: null },
          ],
          keepAlive: false,
        },
      },

      /* 承运运单  运单是运单运单*/
      {
        type: "sub-memu",
        name: "carrierWaybillList",
        path: "carrierWaybill/list",
        component: () =>
          import("../views/carrierWaybill/carrierWaybillList.vue"),
        meta: {
          // thumb: ["承运运单", "运单查询"],
          thumb: [{ text: "运单查询", to: "/home/carrierWaybill/list" }],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      {
        type: "sub-memu",
        name: "carrierWaybillDetails",
        path: "carrierWaybill/list/details/:waybillId",
        component: () =>
          import("../views/carrierWaybill/carrierWaybillDetails.vue"),
        meta: {
          //thumb: ["承运运单", "运单查询", "详情"],
          thumb: [
            { text: "运单查询", to: "/home/carrierWaybill/list" },
            { text: "详情", to: null },
          ],
          keepAlive: false,
        },
      },

      /* 车辆管理 */
      {
        type: "sub-memu",
        path: "vehicle/list",
        component: () => import("../views/vehicle/list.vue"),
        meta: {
          //thumb: ["车辆管理", "车辆列表"],
          thumb: [{ text: "车辆列表", to: "/home/vehicle/list" }],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      /* 合同管理 */
      {
        type: "sub-memu",
        path: "contractManagement/List",
        component: () => import("../views/contractManagement/contractList.vue"),
        meta: {
          // thumb: ["合同管理", "承运合同"],
          thumb: [{ text: "承运合同", to: "/home/contractManagement/List" }],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      /* 司机管理 */
      {
        type: "sub-memu",
        path: "driver/list",
        component: () => import("../views/driver/driverList.vue"),
        meta: {
          //thumb: ["司机管理", "司机列表"],
          thumb: [{ text: "司机列表", to: "/home/driver/list" }],
          keepAlive: true,
          scrollTop: 0,
        },
      },

      {
        type: "sub-memu",
        path: "contractManagement/Detail/:contractId",
        component: () =>
          import("../views/contractManagement/contractDetails.vue"),
        meta: {
          // thumb: ["合同管理", "承运合同", "详情"],
          thumb: [
            { text: "承运合同", to: "/home/contractManagement/List" },
            { text: "详情", to: null },
          ],
          keepAlive: false,
        },
      },

      /* 自营订单 */
      {
        name: "orderQueryList",
        path: "selfOperatedOrder/List",
        component: () => import("../views/selfOperatedOrder/orderQuery.vue"),
        meta: {
          //thumb: ["自营订单", "查询订单"],
          thumb: [{ text: "查询订单", to: "/home/selfOperatedOrder/List" }],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      {
        name: "orderQueryDetails",
        path: "selfOperatedOrder/list/details",
        component: () =>
          import("../views/selfOperatedOrder/orderQueryDetails.vue"),
        meta: {
          //thumb: ["自营订单", "查询订单", "详情"],
          thumb: [
            { text: "查询订单", to: "/home/selfOperatedOrder/List" },
            { text: "详情", to: null },
          ],
          keepAlive: false,
        },
      },
      {
        name: "selfCreatedOrder",
        path: "selfOperatedOrder/selfCreatedOrder",
        component: () =>
          import("../views/selfOperatedOrder/selfCreatedOrder.vue"),
        meta: {
          //thumb: ["自营订单", "自行建单"],
          thumb: [
            {
              text: "创建订单",
              to: "/home/selfOperatedOrder/selfCreatedOrder",
            },
          ],
          keepAlive: false,
        },
      },
      {
        name: "editCarrierOrder",
        path: "selfOperatedOrder/editCarrierOrder",
        component: () =>
          import("../views/selfOperatedOrder/selfCreatedOrder.vue"),
        meta: {
          //thumb: ["自营订单", "自行建单"],
          thumb: [{ text: "修改订单", to: null }],
          keepAlive: false,
        },
      },
      {
        name: "batchCreatedOrder",
        path: "selfOperatedOrder/batchCreatedOrder",
        component: () =>
          import("../views/selfOperatedOrder/batchCreatedOrder.vue"),
        meta: {
          //thumb: ["自营订单", "批量建单"],
          thumb: [
            {
              text: "批量建单",
              to: "/home/selfOperatedOrder/batchCreatedOrder",
            },
          ],
          keepAlive: false,
        },
      },
      {
        name: "planManagement",
        path: "selfOperatedOrder/planManagement",
        component: () =>
          import("../views/selfOperatedOrder/planManagement.vue"),
        meta: {
          thumb: [
            { text: "计划管理", to: "/home/selfOperatedOrder/planManagement" },
          ],
          keepAlive: false,
        },
      },
      {
        name: "planCreated",
        path: "selfOperatedOrder/planCreated",
        component: () => import("../views/selfOperatedOrder/planCreated.vue"),
        meta: {
          thumb: [
            { text: "计划管理", to: "/home/selfOperatedOrder/planManagement" },
            { text: "计划订单", to: "/home/selfOperatedOrder/planCreated" },
          ],
          keepAlive: false,
        },
      },
      //
      {
        path: "selfOperatedSettlement/list",
        component: () =>
          import(
            "../views/selfOperatedSettlement/selfOperatedSettlementList.vue"
          ),
        meta: {
          //thumb: ["自营结算单", "自营结算单管理"],
          thumb: [
            { text: "自营结算单管理", to: "/home/selfOperatedSettlement/list" },
          ],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      {
        path: "selfOperatedSettlement/selfOperatedSettlementDetails/:driverBillId",
        component: () =>
          import(
            "../views/selfOperatedSettlement/selfOperatedSettlementDetails.vue"
          ),
        meta: {
          //thumb: ["自营结算单", "付款单（司机）", "详情"],
          thumb: [
            { text: "付款单（司机）", to: "/home/selfOperatedSettlement/list" },
            { text: "详情", to: null },
          ],
          keepAlive: false,
        },
      },
      {
        path: "selfOperatedSettlement/receiptDetails/:id",
        component: () =>
          import("../views/selfOperatedSettlement/receiptDetails.vue"),
        meta: {
          //thumb: ["自营结算单", "收款单（货主）", "详情"],
          thumb: [
            { text: "收款单（货主）", to: "/home/selfOperatedSettlement/list" },
            { text: "详情", to: null },
          ],
          keepAlive: false,
        },
      },

      //自营设置
      {
        name: "selfOperatedSettings",
        path: "selfOperatedSettings/settingsManagement",
        component: () =>
          import("../views/selfOperatedSettings/selfManagement.vue"),
        meta: {
          // thumb: ["自营设置", "自营管理"],
          thumb: [
            {
              text: "自营管理",
              to: "/home/selfOperatedSettings/settingsManagement",
            },
          ],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      {
        name: "selfOperatedSettingsDetails",
        path: "selfOperatedSettings/settingsManagement/details",
        component: () =>
          import("../views/selfOperatedSettings/selfManagementDetails.vue"),
        meta: {
          //thumb: ["自营设置", "自营管理", '详情'],
          thumb: [
            {
              text: "自营管理",
              to: "/home/selfOperatedSettings/settingsManagement",
            },
            { text: "详情", to: null },
          ],
          keepAlive: false,
        },
      },
      {
        name: "selfContractDetail",
        path: "selfOperatedSettings/selfContractDetail",
        component: () =>
          import("../views/selfOperatedSettings/selfContractDetail.vue"),
        meta: {
          //thumb: ["自营设置", "自营管理", '详情'],
          thumb: [
            {
              text: "自营管理",
              to: "/home/selfOperatedSettings/settingsManagement",
            },
            { text: "合同详情", to: null },
          ],
          keepAlive: false,
        },
      },
      // self operated waybill
      {
        name: "selfOperatedWaybill",
        path: "selfOperatedWaybill/list",
        component: () =>
          import("../views/selfOperatedWaybill/selfOperatedWaybill.vue"),
        meta: {
          //thumb: ["自营运单", "运单查询"],
          thumb: [{ text: "运单查询", to: "/home/selfOperatedWaybill/list" }],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      {
        name: "selfOperatedWaybillDetails",
        path: "selfOperatedWaybill/details/:waybillId",
        component: () =>
          import("../views/carrierWaybill/carrierWaybillDetails.vue"),
        meta: {
          // thumb: ["自营运单", "运单查询", "详情"],
          thumb: [
            { text: "运单查询", to: "/home/selfOperatedWaybill/list" },
            { text: "详情", to: null },
          ],
          keepAlive: false,
        },
      },

      {
        name: "receiptDetailsWayBill",
        path: "receiptDetailsWayBill/:waybillId",
        component: () =>
          import("../views/selfOperatedSettlement/receiptDetailsWayBill.vue"),
        meta: {
          thumb: [
            { text: "收款单（货主）", to: "/home/selfOperatedSettlement/list" },
            // { text: "收款单（货主）详情", to: null },
            { text: "运单详情", to: null },
          ],
          keepAlive: false,
        },
      },
      //承运结算单
      {
        name: "carrierSettlement",
        path: "carrierSettlement/list",
        component: () =>
          import("../views/carrierSettlement/carrierSettlement.vue"),
        meta: {
          //thumb: ["承运结算单", "结算单管理"],
          thumb: [{ text: "结算单管理", to: "/home/carrierSettlement/list" }],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      {
        name: "carrierSettlementPaymentDetails",
        path: "carrierSettlement/list/paymentDetails",
        component: () =>
          import("../views/carrierSettlement/paymentDetails.vue"),
        meta: {
          //thumb: ["承运结算单", "付款单(司机)", "详情"],
          thumb: [
            { text: "付款单(司机)", to: "/home/carrierSettlement/list" },
            { text: "详情", to: null },
          ],
          keepAlive: false,
        },
      },
      {
        name: "carrierSettlementReceiptDetails",
        path: "carrierSettlement/list/receiptDetails",
        component: () =>
          import("../views/carrierSettlement/receiptDetails.vue"),
        meta: {
          //thumb: ["承运结算单", "收款单(平台)", "详情"],
          thumb: [
            { text: "收款单(平台)", to: "/home/carrierSettlement/list" },
            { text: "详情", to: null },
          ],
          keepAlive: false,
        },
      },
      {
        name: "accountingPeriodSetting",
        path: "basicSettings/accountingPeriodSetting",
        component: () =>
          import("../views/basicSettings/accountingPeriodSetting.vue"),
        meta: {
          //thumb: ["基础设置", "账期设置"],
          thumb: [
            {
              text: "账期设置",
              to: "/home/basicSettings/accountingPeriodSetting",
            },
          ],
          keepAlive: false,
        },
      },
      {
        name: "accountManagement",
        path: "basicSettings/accountManagement",
        component: () => import("../views/basicSettings/accountManagement.vue"),
        meta: {
          //thumb: ["基础设置", "账号管理"],
          thumb: [
            { text: "账号管理", to: "/home/BasicSettings/accountManagement" },
          ],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      {
        name: "insure",
        path: "basicSettings/insure",
        component: () => import("../views/basicSettings/insure.vue"),
        meta: {
          //thumb: ["基础设置", "账号管理"],
          thumb: [{ text: "保险咨询管理", to: "/home/BasicSettings/insure" }],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      {
        name: "roleManagement",
        path: "basicSettings/roleManagement",
        component: () => import("../views/basicSettings/roleManagement.vue"),
        meta: {
          // thumb: ["基础设置", "角色管理"],
          thumb: [
            { text: "角色管理", to: "/home/basicSettings/roleManagement" },
          ],
          keepAlive: false,
        },
      },
      {
        name: "address",
        path: "basicSettings/address",
        component: () => import("../views/basicSettings/address.vue"),
        meta: {
          // thumb: ["基础设置", "角色管理"],
          thumb: [{ text: "收货地址管理", to: "/home/BasicSettings/address" }],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      {
        name: "addressExamine",
        path: "basicSettings/addressExamine",
        component: () => import("../views/basicSettings/addressExamine.vue"),
        meta: {
          // thumb: ["基础设置", "角色管理"],
          thumb: [
            {
              text: "收货地址修改审核",
              to: "/home/BasicSettings/addressExamine",
            },
          ],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      {
        name: "feedback",
        path: "basicSettings/feedback",
        component: () => import("../views/basicSettings/feedback.vue"),
        meta: {
          //thumb: ["基础设置", "意见反馈"],
          thumb: [{ text: "意见反馈", to: "/home/basicSettings/feedback" }],
          keepAlive: false,
        },
      },
      {
        name: "personalSettings",
        path: "personalSettings",
        component: () => import("../views/basicSettings/personalSettings.vue"),
        meta: {
          //thumb: ["个设置"],
          thumb: [{ text: "个人设置", to: "/home/personalSettings" }],
          keepAlive: false,
        },
      },
      {
        name: "accountCreatAndBind",
        path: "accountCreatAndBind",
        component: () =>
          import("../views/basicSettings/accountCreatAndBind.vue"),
        meta: {
          //thumb: ["个设置"],
          thumb: [{ text: "账号创建与绑定", to: "/home/accountCreatAndBind" }],
          keepAlive: false,
        },
      },
      {
        name: "accountAmount",
        path: "accountAmount",
        component: () => import("../views/basicSettings/accountAmount.vue"),
        meta: {
          thumb: [{ text: "资金流水列表", to: "/home/accountAmount" }],
          keepAlive: true,
          scrollTop: 0,
        },
      },
    ],
  },
  {
    path: "/dataStatistics",
    name: "dataStatistics",
    component: HomeView,
    children: [
      {
        path: "dirver",
        component: () => import("../views/dataStatistics/dirver.vue"),
        meta: {
          //thumb: ["消息中心"],
          thumb: [
            {
              text: "司机费用统计",
              to: "/dataStatistics/dirver",
            },
          ],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      {
        path: "Coststatistics",
        component: () => import("../views/dataStatistics/Coststatistics.vue"),
        meta: {
          //thumb: ["消息中心"],
          thumb: [
            {
              text: "费用统计",
              to: "/dataStatistics/Coststatistics",
            },
          ],
          keepAlive: true,
          scrollTop: 0,
        },
      },
    ],
  },
  {
    path: "/messageCenter",
    name: "messageCenter",
    component: HomeView,
    children: [
      {
        path: "messageCenterList",
        component: () => import("../views/messageCenter/messageCenterList.vue"),
        meta: {
          //thumb: ["消息中心"],
          thumb: [
            {
              text: "消息中心",
              to: "/messageCenter/messageCenterList",
            },
          ],
          keepAlive: true,
          scrollTop: 0,
        },
      },
      {
        path: "messageCenterList/Details",
        component: () =>
          import("../views/messageCenter/messageCenterListDetails.vue"),
        meta: {
          //thumb: ["消息中心","消息详情"],
          thumb: [
            {
              text: "消息中心",
              to: "/messageCenter/messageCenterList",
            },
            {
              text: "消息详情",
              to: "/messageCenter/messageCenterList/Details",
            },
          ],
          keepAlive: false,
        },
      },
    ],
  },
];

const router = new VueRouter({
  routes,
  mode: "hash",
});

//全局进度条的配置
NProgress.configure({
  showSpinner: false, //加载微调器设置,默认为true
});
// 全局路由守卫
router.beforeEach((to, from, next) => {
  NProgress.start();
  let type = to.meta.permission;
  //console.log(to.path);
  if (to.path == "/home/vehicleSafetyManagement") {
    // 车辆安全管理路由不跳转
    return false;
  } else {
    next();
  }

  // if (to.path === "/Login") {
  //   // 清除本地储存token
  //   localStorage.clear();
  //   // 放行
  //   next();
  // } else if (to.meta.need_token === true) {
  //   let token = localStorage.getItem("token");
  //   if (token === "" || token === null) {
  //     next("/Login");
  //   } else {
  //     // 有token则放行
  //     next();
  //   }
  // } else {
  //   // 不需要验证
  // }
});
// 全局后置守卫
router.afterEach((to, from, next) => {
  NProgress.done();
  ////console.log(NProgress.done());
  ////console.log(111);
});

export default router;
